package app.beit.finportal.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import app.beit.finportal.entity.RelativeWebPrograms;

public class RelativeWebProgramsDao extends BaseDao<RelativeWebPrograms> {

	@SuppressWarnings("unchecked")
	public List<RelativeWebPrograms> getAll() throws Exception{
		final Session session = super.sessionFactory.openSession();
		final List<RelativeWebPrograms> result = session.createQuery("from RelativeWebPrograms").list();
		session.close();
		
		return result;
	}

	@SuppressWarnings("unchecked")
	public List<RelativeWebPrograms> getAllByTypesBackdoor(final String type) throws Exception{
		final Session session = super.sessionFactory.openSession();
		final Query query = session.createQuery("from RelativeWebPrograms where types=:types");
		query.setParameter("types", type);
		final List<RelativeWebPrograms> results = query.list();
		session.close();
		
		return results;
	}

	@SuppressWarnings("unchecked")
	public List<RelativeWebPrograms> getAllByTypes(final String type) throws Exception{
		final Session session = super.sessionFactory.openSession();
		final Query query = session.createQuery("from RelativeWebPrograms where status='1' and types=:types order by updated_date desc");
		query.setParameter("types", type);
		final List<RelativeWebPrograms> results = query.list();
		session.close();
		
		return results;
	}

	@SuppressWarnings("unchecked")
	public List<RelativeWebPrograms> getAllByTypesLastestDate(final String type) throws Exception{
		final Session session = super.sessionFactory.openSession();
		final Query query = session.createQuery("from RelativeWebPrograms where status='1' and types=:types order by updated_date desc");
		query.setParameter("types", type);
		query.setFirstResult(0);
		query.setMaxResults(8);
		final List<RelativeWebPrograms> results = query.list();
		session.close();
		
		return results;
	}
}
